//
//  HZNavViewController.m
//  HZTC_Stock
//
//  Created by MayerF on 17/3/9.
//  Copyright © 2017年 MayerF. All rights reserved.
//

#import "HZNavViewController.h"
//#import "HZMeViewController.h"
#import "UINavigationBar+GradientColor.h"

@interface HZNavViewController ()<UIGestureRecognizerDelegate>

@end

@implementation HZNavViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [UINavigationBar appearance].translucent = NO;
//    self.edgesForExtendedLayout = UIRectEdgeAll;
    [UINavigationBar appearance].barTintColor = kMYHexToRGB(0xef1d2e,1);
    
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.interactivePopGestureRecognizer.delegate = self;
    [[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setShadowImage:[UIImage new]];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.viewControllers.count == 0) {
        [super pushViewController:viewController animated:animated];
        return;
    }
    [self p_resetBackStyle:viewController];
    viewController.hidesBottomBarWhenPushed = YES;
    self.navigationBarHidden = NO;
    self.navigationBar.translucent = NO;
    [self.navigationBar resetNav];
    [super pushViewController:viewController animated:animated];
}

#pragma mark -
#pragma mark action
- (BOOL)p_checkUserIsLogin
{
    BOOL islogin = [HZUserManager manager].isLogined;
    if (!islogin) {
        UIViewController *loginVC = [[MYRouter shared] matchController:kRouterLogin];
        [self.topViewController presentViewController:loginVC animated:YES completion:nil];
    }
    return islogin;
}

- (void)p_resetBackStyle:(UIViewController *)viewController
{
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
    [leftButton setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
    leftButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 20);
    [leftButton addTarget:self action:@selector(backBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
}

- (void)backBtnOnClick
{
    [self popViewControllerAnimated:YES];
}

- (BOOL)shouldAutorotate
{
    return [[self.viewControllers lastObject] shouldAutorotate];
}
//ccc 引用错误屏蔽
//- (BOOL)prefersStatusBarHidden{
//    return [[self.viewControllers lastObject] prefersStatusBarHidden];
//}
- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleLightContent;
}

@end
